package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "车辆模块")
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @ApiOperation("查询车辆")
    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("vehicleQuery={}"+vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @ApiOperation("保存车辆")
    @PostMapping("save")
    public JsonResult saveVechicle(VehicleSaveParam vehicleSaveParam){

        log.debug("vehicleQuery={}"+vehicleSaveParam);
        vehicleService.saveVechicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除车辆")
    @DeleteMapping("{id}/delete")
    public JsonResult deleteVechicle(@PathVariable Long id){
        vehicleService.deleteVechicleById(id);
        return JsonResult.ok();
    }

    @ApiOperation("解绑车辆")
    @PostMapping("unbind/{vehicleId}")
    public JsonResult unbindVehicle(@PathVariable Long vehicleId){
        log.debug("解绑车辆:VehicleId",vehicleId);
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();
    }

    @ApiOperation("绑定车辆")
    @PostMapping("bind/{geofenceId}/{vehicleId}")
    public JsonResult bindVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定车辆:geofenceId,vehicleId",geofenceId,vehicleId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }
}
